%table#transaction-list.table-striped
  %tr.heading
    %th= sortable(path_to_transactions, :start_date, t('.start_date'))
    %th= sortable(path_to_transactions, :end_date, t('.end_date'))
    %th= sortable(path_to_transactions, :user_id, t('.user'))
    %th= sortable(path_to_transactions, :book_id, t('.book'))
    - if current_user.admin?
      %th= sortable(path_to_transactions, :status, t('.status'))
    %th

  - @transactions.each do |transaction|
    %tr.transaction_row{transaction_id: transaction.id}
      %td.start_date= transaction.start_date
      %td.end_date= transaction.end_date
      %td.user= transaction.user.email
      %td.book= transaction.book.name
      - if current_user.admin?
        %td.state
          = select_tag :status, options_for_select(Transaction::STATES, transaction.status)
      %td.actions
        - if Transaction::REMINDER_ENABLE.include?(transaction.status) && current_user.admin?
          = link_to t('.remind'), remind_path(id: transaction.id), method: :put
          = "|"
        - if !(current_user.admin? || transaction.status != Transaction::STATES[:WAITING])
          = link_to t('.destroy'), 
            book_transaction_path(book_id: transaction.book_id, id: transaction.id), 
            method: :delete, data: {confirm: "Are you sure?"}
        - else
          = Transaction::REVERSE_STATES[transaction.status]

%p= will_paginate @transactions, renderer: BootstrapPagination::Rails

